﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="QOrder.aspx.cs" Inherits="WebApp.QOrder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>工作单信息</title>
    <link href="css/newStyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="js/Global.js"></script>

    <script type="text/javascript" src="js/mypage.js"></script>

    <script type="text/javascript" src="js/datecontrol.js"></script>

</head>
<body onload="init();">
    <form id="form1" runat="server">
    <div style="text-align: left; width: 1000px; padding-left: 20px; padding-top: 20px;">
        <div>
            接单时段
            <input id="TxtSDate" type="text" style="width: 100px" readonly="readonly" onclick="SelectDate(this)" />
            -
            <input id="TxtEDate" type="text" style="width: 100px" readonly="readonly" onclick="SelectDate(this)" />&nbsp;&nbsp;
            流程状态：<select id="SlctOrderStatus">
            </select>&nbsp;&nbsp; 装柜形式：<select id="SlctStowageMethod">
            </select>&nbsp;&nbsp; 客服：<select id="SlctAgent">
            </select>&nbsp;&nbsp; 业务：<select id="SlctOperator">
            </select>&nbsp;&nbsp;<br />
            报关状态：<select id="SlctCustomsStatus">
            </select>&nbsp;&nbsp; 是否退税：<select id="SlctDrawBack"></select>&nbsp;&nbsp; 单据状态：<select
                id="SlctDeleteFlag"></select>&nbsp;&nbsp; 委托方：<input id="TxtClient" type="text" style="width: 100px" />&nbsp;&nbsp;
            作业号：<input id="TxtCode" type="text" style="width: 100px" />&nbsp;&nbsp; 提单号：<input
                id="TxtCCode" type="text" style="width: 100px" />&nbsp;&nbsp; 核销单号：：<input id="TxtCheckOffCode"
                    type="text" style="width: 100px" />&nbsp;&nbsp; 柜号：<input id="TxtCaseCode" type="text"
                        style="width: 100px" />&nbsp;&nbsp;
            <input type="button" id="BtnSearch" value="查询" onclick="refreshList()" />
            &nbsp;<input type="button" id="BtnAddTask" value="新增任务" onclick="addTask()" />
        </div>
        <div>
            <div id="divResult">
            </div>
            <div id="divPaging" class="ListPager">
            </div>
        </div>
    </div>
    
    </form>
</body>
</html>

<script type="text/javascript">
    function resetFrm() {
        $("frmTskTitle").value = "";
        $('frmTskId').value = "0";
        $('frmClient').value = "0";
        $('frmLeader').value = "0";
        $("Button1").style.display = "inline";
        $("frmStatus").innerHTML = "";
        $("TrTskResultView").style.display = "none";
        $("frmTskResult").innerHTML = "";
        $("frmTskComment").innerHTML = "";
        $("frmTskDec").value = "";
        $("form1").reset();
        initDate();
    }
    function viewTask(flag, tId) {
        editTask(tId);

        var a = $("divEditForm").getElementsByTagName("input");
        for (var i = 0; i < a.length; i++) {
            if (a[i].id != 'Button4')
                a[i].disabled = flag;
        }

        var b = $("divEditForm").getElementsByTagName("select");
        for (var i = 0; i < b.length; i++) {
            b[i].disabled = flag;
        }

        //$("frmDisable").disabled=flag;
        $("divEditForm").style.display = "inline";
    }

    function addTask() {
        resetFrm();
        $("divEditForm").style.display = "inline";
    }

    function delTask(tId) {
        if (window.confirm("确认删除该项吗？")) {
            var drtn = TaskList.DelTask(tId).value;
            if (drtn) {
                alert("删除成功！");
                refreshList();
            }
            else
                alert("删除失败！");
        }
    }

    function editTask(tId) {
        $("Button1").style.display = "none";
        $("divEditForm").style.display = "inline";
        var rtn = TaskList.GetTask(tId).value;
        if (rtn && rtn != null) {
            $("frmTskId").value = ShowVal(rtn.TskId);
            $("frmTskDate").value = (ShowVal(rtn.TskDate) == "") ? "" : new Date(ShowVal(rtn.TskDate)).toLocaleDateString();
            $("frmTskTitle").value = ShowVal(rtn.TskTitle);
            $("frmAgentName").value = getUName(rtn.AgentId);
            $("frmAgent").value = rtn.AgentId;
            $("frmLeaderName").value = getUName(rtn.Leader);
            $("frmLeader").value = rtn.Leader;
            $("frmClientName").value = getTrdrName(rtn.ClientId);
            $("frmClient").value = rtn.ClientId;
            $("frmTskDec").value = ShowVal(rtn.TskDec);
            //$("ifrmDesc").document.location.reload();
            ifrmDescName.document.location.reload();

            $("frmTskResult").innerHTML = ShowVal(rtn.TskResult);
            $("frmTskComment").innerHTML = ShowVal(rtn.TskComment);
            if (GetIntVal(rtn.Status)) {
                $("frmStatus").innerHTML = "已审";
                $("TrTskResultView").style.display = "inline";
            }
            else {
                $("frmStatus").innerHTML = "未审";
                $("TrTskResultView").style.display = "none";
            }
        }
    }

    function getUName(uId) {
        var rtn = TaskList.GetUserName(uId).value;
        if (rtn)
            return rtn;
        return "";
    }

    function getTrdrName(tId) {
        var rtn = TaskList.GetTraderName(tId).value;
        if (rtn)
            return rtn;
        return "";
    }

    function SaveTask(tId, exit) {
        var tskTitle = $("frmTskTitle").value.Trim();
        var tskDate = $("frmTskDate").value;

        if (tskDate == "") {
            alert("请输任务时间！");
            $("frmTskDate").focus();
            return;
        }

        if (tskTitle == "") {
            alert("请输入任务标题！");
            $("frmTskTitle").focus();
            return;
        }

        if (GetIntVal($("frmAgent").value) == 0) {
            alert("请填写业务员！");
            $("frmAgentName").focus();
            return;
        }

        if (GetIntVal($("frmLeader").value) == 0) {
            alert("请填写审批人！");
            $("frmLeaderName").focus();
            return;
        }

        if (GetIntVal($("frmClient").value) == 0) {
            alert("请填写客户！");
            $("frmClientName").focus();
            return;
        }


        var rtn = TaskList.EditTask(tId, tskTitle, tskDate, GetIntVal($("frmAgent").value), GetIntVal($("frmLeader").value),
        GetIntVal($("frmClient").value), $("frmTskDec").value.Trim()).value;

        if (rtn) {
            if (tId > 0)
                alert("修改成功");
            else
                alert("新增成功");

            refreshList();
        }
        else
        { alert("操作失败！"); return; }

        if (exit) {
            $('divEditForm').style.display = 'none';
            resetFrm();
        }
        else
            $("frmTskTitle").focus();
    }
</script>

<script type="text/javascript">
    //分页相关
    g_PageIndex = 0;
    g_PageSize = 10;
    g_TotalCount = 0;
    function getListHtml(deleteFlag, orderCode, cCode, sDate, eDate, orderStatus, agent, bizMan, stowageMethod, clientName,
    isDrawback, customsStatus, checkOffCode, caseCode) {
        var html = '<table cellspacing="1" cellpadding="0" class="TableClass">' +
                       '    <tr class="TableHeader">' +
                       '        <td style="width: 180px; height: 25px;" align="center">' +
                       '            <strong>作业单号</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>提单号</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>委托方</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>交单</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>查验</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>放行</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>通知</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>工作状态</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                       '            <strong>报关状态</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>申报时间</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>业务员</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>客服</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>放行时间</strong></td>' +
                       '        <td style="width: 80px; height: 25px;" align="center">' +
                        '            <strong>取消</strong></td>' +
                       '        <td style="width: 100px; height: 25px;" align="center">' +
                       '            <strong>操作</strong></td>' +
                       '    </tr>';
        //var res = TaskList.GetTaskList(g_PageIndex, g_PageSize, sDate, eDate, keyWord).value;
        var datas = WebApp.QOrder.GetList(deleteFlag, orderCode, cCode, sDate, eDate, orderStatus, agent, bizMan, stowageMethod, clientName,
    isDrawback, customsStatus, checkOffCode, caseCode, g_PageSize, g_PageIndex).value;
        if (datas) {
            var res = datas.DataList;
            g_TotalCount = datas.RecordCount;
            if (res) {
                for (var i = 0, count = res.length; i < count; ++i) {
                    html += '<tr height="25">' +
                            '    <td class="TableItem">' +
                            '<a href="#" onclick="viewTask(true,' + res[i].OrderId + ')">' + ShowVal(res[i].OrderCode) + '</a></td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].CCode) + '</td>' +
                             '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].ClientName) + '</td>' +
                             '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].IsOffer) + '</td>' +
                             '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].IsCheck) + '</td>' +
                             '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].IsPass) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].IsNotice) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].OrderStatus) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].CustomsStatus) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + new Date(ShowVal(res[i].ApplyDate)).toLocaleDateString() + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].BizmanName) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].AgentName) + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + new Date(ShowVal(res[i].PassTime)).toLocaleDateString() + '</td>' +
                            '    <td class="TableItem">' +
                            '        ' + ShowVal(res[i].DeleteFlag) + '</td>' +
                            '    <td class="TableItem">' +
                            '<a href="#" onclick="viewTask(false,' + res[i].OrderId +
                            ')"><u>编辑</u></a> <a href="#" onclick="delTask(' + res[i].OrderId + ')"><u>删除</u></a></td>' +
                            '</tr>';
                }
            }
        }
        html += '                   </tr>';
        html += '</table>';
        $("divResult").innerHTML = html;
        
    }


    //显示分页
    setPagingHtml = function() {
        var tep_page = new funGetPaginationHtml();
//        var rtnCount = TaskList.GetCount(sDate, eDate, keyWord).value;
//        if (rtnCount)
//            g_TotalCount = rtnCount;
//        else
//            g_TotalCount = 0;
        $("divPaging").innerHTML = tep_page.GetPaginationHtml(g_TotalCount, g_PageSize, g_PageIndex, "goToPage");
        //$("spanTotalRecord").innerHTML = g_TotalCount;
    }

    goToPage = function(index) { //debugger;
        g_PageIndex = index;
        refreshList();
    }


    ///刷新数据
    refreshList = function() {
        //var keyWord = $("TxtKeyword").value;
        var sDate = $("TxtSDate").value;
        var eDate = $("TxtEDate").value;
        var orderStatus = $("SlctOrderStatus").value;
        var stowageMethod = $("SlctStowageMethod").value;
        var agent = $("SlctAgent").value;
        var operator = $("SlctOperator").value;
        var customsStatus = $("SlctCustomsStatus").value;
        var drawBack = $("SlctDrawBack").value;
        var deleteFlag = $("SlctDeleteFlag").value;
        var client = $("TxtClient").value;
        var code = $("TxtCode").value;
        var cCode = $("TxtCCode").value;
        var checkOffCode = $("TxtCheckOffCode").value;
        var caseCode = $("TxtCaseCode").value;
        var bizMan;
        var clientName;
        getListHtml(deleteFlag, code, cCode, sDate, eDate, orderStatus, agent, bizMan, stowageMethod, clientName,
    drawBack, customsStatus, checkOffCode, caseCode);
        setPagingHtml();
    }

    function showChoseTrader(obj) {
        var loc_x = obj.clientX + 20;
        var loc_y = obj.clienY + 20;
        window.open("ChoseTrader.aspx?key=" + obj.id, "", "width=500,height=500,top=" + loc_y + ",left=" + loc_x + ",scrollbars=1,location=0,status=1,resizable=0")
    }

    function showChoseAgent(obj) {
        var loc_x = obj.clientX + 20;
        var loc_y = obj.clienY + 20;
        window.open("ChoseUser.aspx?key=" + obj.id, "", "width=500,height=500,top=" + loc_y + ",left=" + loc_x + ",scrollbars=1,location=0,status=1,resizable=0")
    }

    function init() {
        initDate();
        refreshList();
    }

    function initDate() {
        var date = new Date();
        $("TxtSDate").value = DateAdd(date, 'm', -3).Format("yyyy-MM-dd");
        $("TxtEDate").value = date.Format("yyyy-MM-dd");
        //$("frmTskDate").value = date.Format("yyyy-MM-dd");
    }

    function getStatusName(status) {
        if (status)
            return "已审"
        return "未审"
    }
</script>

